IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CompetitionDataValidation]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[CompetitionDataValidation]
GO

-- exec CompetitionDataValidation 6
CREATE procedure [dbo].[CompetitionDataValidation]
(
	@CompetitionId int,
	@ErrorText varchar(1000) = '' out
)
/*
23.09.2014 - Vytvorenie
*/
as begin
	
	/* kontrolny select
	select 
		p.StartNumber,
		p.Surname,
		dl.Name
	from Performances p
	inner join DisciplineList dl on dl.ID = p.DisciplineListId and dl.CategoryId > 0
	where dl.CompetitionId = 6 */

	select * from 
	(
		select 
			count(p.StartNumber) as Number,
			max(p.StartNumber) as StartNumber,
			max(p.Surname) as Surname,
			max(dl.Name) as DisciplineListName 
		from Performances p
		inner join DisciplineList dl on dl.ID = p.DisciplineListId and dl.CategoryId > 0
		where dl.CompetitionId = @CompetitionId
		group by p.StartNumber
	) 
	as tab
	where tab.Number > 1
	order by tab.Number asc

end
go